import { HttpStatus } from '.'

/**
 * HttpException 是一个继承原生Error错误对象的 内置错误对象
 */
export class HttpException extends Error {
  constructor(public messageOrResponse: string | object, public status: number) {
    super()
  }

  /**
   * 响应JSON
   */
  getResponse() {
    return this.messageOrResponse
  }

  /**
   * 响应状态码
   */
  getStatus() {
    return this.status
  }
}

// 继承 HttpException 的 BadRequestException 子类
export class BadRequestException extends HttpException {
  constructor(message: string, error?: string) {
    super({ message, error, statusCode: HttpStatus.BAD_REQUEST }, HttpStatus.BAD_REQUEST);
  }
}
